$(document).ready(function(){
	FIXED_ASSETS_NATURE();//查询资产性质
	FIXED_ASSETS_TYPE();//查询资产类型
	FA_STATUS();
	cw.common.getUserSession(loadT_FIXED_ASSETS_DETAIL);
})

//查询资产类型
var FIXED_ASSETS_TYPE = function(){
	cw.common.getDictByPage('FIXED_ASSETS_TYPE','','#FIXED_ASSETS_TYPE',printFIXED_ASSETS_TYPE)
}
var printFIXED_ASSETS_TYPE = function(obj,result,i){
	$(result).append('<option value="'+obj.TYPE_ID+'">'+obj.TYPE_NAME+'</option>');
}
//查询资产性质
var FIXED_ASSETS_NATURE = function(){
	cw.common.getDictByPage('FIXED_ASSETS_NATURE','','#FIXED_ASSETS_NATURE',printFIXED_ASSETS_NATURE)
}
var printFIXED_ASSETS_NATURE = function(obj,result,i){
	$(result).append('<option value="'+obj.TYPE_ID+'">'+obj.TYPE_NAME+'</option>');
}

//查询资产状态
var FA_STATUS = function(){
	cw.common.getDictByPage('CHANGE_TYPE','','#FA_STATUS',printFA_STATUS)
}
var printFA_STATUS = function(obj,result,i){
	$(result).append('<option value="'+obj.TYPE_ID+'">'+obj.TYPE_NAME+'</option>');
}

//载入资产详细信息
function loadT_FIXED_ASSETS_DETAIL(){
	var BARCODE=$("#BARCODE").val();
	if(BARCODE==undefined)BARCODE="";
	
	var FIXED_ASSETS_NAME=$("#FIXED_ASSETS_NAME").val();
	if(FIXED_ASSETS_NAME==undefined)FIXED_ASSETS_NAME="";
	
	var FIXED_ASSETS_TYPE=$("#FIXED_ASSETS_TYPE").val();
	
	var STOCK_PRICE1=$("#STOCK_PRICE1").val();
	if(STOCK_PRICE1==undefined)STOCK_PRICE1="";
	var STOCK_PRICE2=$("#STOCK_PRICE2").val();
	if(STOCK_PRICE2==undefined)STOCK_PRICE2="";
	var re = /^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/; 
	if(STOCK_PRICE1!=""){
		if(!re.test(STOCK_PRICE1))
		{
			alert("价格1为非数字！");return;
		}
	}
	if(STOCK_PRICE2!=""){
		if(!re.test(STOCK_PRICE2))
		{
			alert("价格2为非数字！");return;
		}
	}
	var REMARK=$("#REMARK").val();
	if(REMARK==undefined)REMARK="";
	
	var FA_STATUS = $("#FA_STATUS").val();
	var FIXED_ASSETS_NATURE = $("#FIXED_ASSETS_NATURE").val();
	var url = cw.common.path + '/json?action=QUERY_T_FIXED_ASSETS_DETAILBY_PAGER_ACTION';
	url += "&BARCODE="+BARCODE+"&FIXED_ASSETS_TYPE="+FIXED_ASSETS_TYPE;
	url += "&STOCK_PRICE1="+STOCK_PRICE1+"&STOCK_PRICE2="+STOCK_PRICE2;
	url += "&REMARK="+REMARK+"&FIXED_ASSETS_NAME="+FIXED_ASSETS_NAME;
	url+="&FA_STATUS="+FA_STATUS+"&FIXED_ASSETS_NATURE="+FIXED_ASSETS_NATURE;
	url+="&SEQ_FIELD="+$("#SEQ_FIELD").val()+"&SEQ_WAY="+ $("#SEQ_WAY").val();
	var xmlname = "T_FIXED_ASSETS_DETAIL";
	var pagePanel='#T_FIXED_ASSETS_DETAIL_pager';
	var result='#T_FIXED_ASSETS_DETAIL_LIST';
	var pageSize=10;
	var defaultHtml='<li><em style="text-align: center;width:100%">没有搜索到您要查询的数据...</em></li>';
	cw.common.changePage(url,pageSize,xmlname,result,fn_queryT_FIXED_ASSETS_DETAILLIST,pagePanel,defaultHtml);
}
var fn_queryT_FIXED_ASSETS_DETAILLIST = function(obj,result,i){
	var str='<li id="bar_'+obj.BARCODE+'">';
	str+='<em style="width: 7%; text-align: center;">'+obj.BARCODE+'</em>';
	str+='<em style="width: 8%; text-align: center;">'+obj.FIXED_ASSETS_NAME+'</em>';
	str+='<em style="width: 7%; text-align: center;">'+cw.common.toChar(obj.STOCK_DATE,'yyyy-mm-dd')+'</em>';
	str+='<em style="width: 7%; text-align: center;">'+obj.STOCK_PRICE+'</em>';
	str+='<em style="width: 8%; text-align: center;">'+obj.FIXED_ASSETS_TYPE_NAME+'</em>';
	str+='<em style="width: 8%; text-align: center;">'+obj.FIXED_ASSETS_NATURE_NAME+'</em>';
	str+='<em style="width: 8%; text-align: center;">'+obj.DEPARTMENT_NO_NAME+'</em>';
	str+='<em style="width: 8%; text-align: center;">'+obj.WITH_MANANGER_NAME+'</em>';
	str+='<em style="width: 8%; text-align: center;">'+obj.USE_MANANGER+'</em>';
	str+='<em style="width: 7%; text-align: center;">'+obj.WARRANTY+'</em>';
	str+='<em style="width: 6%; text-align: center;">'+obj.FA_STATUS_NAME+'</em>';
	
	str+='<em style=" text-align: center;"><a href="detail.html?ID='+obj.ID+'">查看</a>';
	str+=' - <a href="../check/print_out_p.html?STATUS='+obj.FA_STATUS+'&ID='+obj.ID+'" target="_blank">打印出库单</a></em>';
	
	str+='</li>';
	$(result).append(str);
}
function printBarCode(barcode){
		xxxx.open_port('TSC TTP-244CE');
        xxxx.clear_buffer();
        xxxx.send_command('DIRECTION 1');
        xxxx.setup_('60','35','4','9','0','2','0');
        xxxx.windows_font(60, 50, 30, 0, 2, 0, '黑体','三盛地产集团'); 
        xxxx.send_command('PDF417 0,100,350,200,0,"'+barcode+'"');
        xxxx.windows_font(60, 200, 30, 0, 2, 0, '黑体','"'+ barcode+'"'); 
        xxxx.print_label('1', '1');
      	//xxxx.download_pcx('C:/UL.PCX','UL.PCX');
       	//xxxx.send_command('PUTPCX 100,250,\'UL.PCX\'');
        //xxxx.send_command("BAR 400,200,300,100");
		//xxxx.send_command("BOX 10,300,300,300,5");
      	xxxx.close_port();
		
		/**
		$.post(cw.common.path + '/json',
		{
			action : 'PRINT_BARCODE_ACTION',
			BARCODE : barcode
		}, function(data){
			if (data.success) {
				alert('打印成功');
			} else {
				alert(data.errors.errmsg);
			}
		}, 'json');
		*/
}
//批量删除
function batchDel(){
	if(getCheckedNum('check')==0){
		alert('请选择要删除的资产条码');
		return;
	}
	if(!confirm('确定要删除资产吗？')){
		return;
	}
	var barcodeA = getCheckedVal('check').split(',');
	$.post(cw.common.path + '/json',
		{
			action : 'BATCH_DELETE_T_FIXED_ASSETS_DETAIL_ACTION',
			BARCODE : barcodeA
		}, function(data){
			if (data.success) {
				for(var i=0;i<barcodeA.length;i++)
				{
					$("#bar_"+barcodeA[i]).remove();
				}
				alert('批量删除低值易耗品成功');
			} else {
				alert(data.errors.errmsg);
			}
		}, 'json');
}
//批量删除
function del(barcode){
	$.post(cw.common.path + '/json',
		{
			action : 'DELETE_T_FIXED_ASSETS_DETAIL_ACTION',
			BARCODE : barcode
		}, function(data){
			if (data.success) {
					$("#bar_"+barcode).remove();
					alert('批量删除低值易耗品成功');
			} else {
				alert(data.errors.errmsg);
			}
		}, 'json');
}